﻿/// <reference path="../scripts/jquery-1.11.2.min.js" />
/// <reference path="../scripts/bootstrap.min.js" />

if (typeof ($) != "undefined" && $) {
    //验证用户
    CheckUser();
    $(document).ready(onReady);

}

function onReady() {
    var ua = navigator.userAgent.toLowerCase();
    var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1);

    $.ajax({
        type: "get",
        url: "api/common.ashx?ac=cpscheme&k=" + Math.random(),
        beforeSend: function () {
            $('#loadingToast').show();
        },
        error: function () {
            showToast("数据加载失败");
        },
        success: function (data) {
            var list = eval("(" + data + ")");
            for (var i = 0; i < list.length; i++) {
                var o = list[i];
                var htm = '<div class="stamp stamp01">';
                htm += '<div class="par">';
                htm += '<sub class="sign"></sub><span>洗车券×' + o.Quantity + '</span><sub></sub><p>';
                htm += '' + o.Explain + '<br /> 有效期：' + o.ValidDays + '天</p>';
                htm += '</div>';
                htm += '<div class="copy">';
                htm += '￥' + o.PrePrice + '.00<p><span class="fline">￥' + o.OldPrice + '.00</span><br />(' + o.Scope + ')<br />';
                htm += '<input type="radio" name="radio" onclick="buy(' + o.SchemeID + ',' + o.PrePrice + ')" data-labelauty="购买" />';
                htm += '</p>';
                htm += '</div>';
                htm += '</div>';

                $("#cplist").append(htm);
            }
            $(':input').labelauty();
        },
        complete: function () {
            $('#loadingToast').hide();
        }
    });

    $("#btnbuy").click(function () {
        var cpsid = $("#cpsid").val();
        if (cpsid == 0) {
            alert('请选择购买套餐');
        }
        else {
            window.parent.location.href = 'JsApiPayPage2.aspx?SchemeID=' + cpsid;
        }
    });
}

function buy(id, money) {
    $("#pay").html('￥' + money);
    $("#cpsid").val(id);
}

